Installing Modules in Axir Smart Account
This guide covers how to install different modules in your Axir smart account.
Prerequisites
First, import the required dependencies:
import { AxirCore } from "axr-erc4337-sdk";
import { ethers } from "ethers";
import { type Hex } from "viem";
Implementation
1. Initialize AxirCore
First, create an instance of AxirCore:
const axirCore = new AxirCore(
process.env.PRIVATE_KEY as Hex,
process.env.RPC_URL as string,
process.env.BUNDLER_URL as string,
BigInt(0), // nonce
"baseSepolia" // network name
);
2. Install Social Recovery Module
// Prepare module installation UserOperation
const moduleInstallOp = await axirCore.generateInstallModuleUserOperation(
socialRecoveryModuleAddress,
2, // Module type for social recovery
[
{ type: "uint256", value: 2 }, // Number of guardians required
{
type: "address[]",
value: [
"0xF7df43751C27f55A3077557D0579Ef7ebFffc7FC",
"0x848ef0Bd2491255B87133d71f01029CEaFF2986b",
],
},
],
{
callGasLimit: BigInt(1000000),
verificationGasLimit: BigInt(2000000),
preVerificationGas: BigInt(1000000),
},
usePaymaster,
paymasterType
);
// Estimate gas costs
const installGasEstimate = await axirCore.estimateUserOperationGas(
moduleInstallOp,
usePaymaster,
paymasterType
);
console.log("Gas Estimation for module installation:");
if (installGasEstimate.totalGasFeeInEth) {
console.log(
`Estimated gas fee in ETH: ${ethers.formatEther(
installGasEstimate.totalGasFeeInEth
)} ETH`
);
}
// Execute the module installation
const txHash = await axirCore.executeUserOperation(moduleInstallOp);
console.log("Module installation hash:", txHash);
// Verify installation
const isInstalled = await axirCore.isModuleInstalled(
socialRecoveryModuleAddress,
2,
"0x"
);
console.log("Is module installed?", isInstalled);
3. Install ECDSA Validator Module
// Prepare validator module installation
const validatorInstallOp = await axirCore.generateInstallModuleUserOperation(
ecdsaValidatorAddress,
1, // Module type for validator
"0x", // No initialization data needed
undefined,
usePaymaster,
paymasterType
);
// Estimate gas costs
const validatorGasEstimate = await axirCore.estimateUserOperationGas(
validatorInstallOp,
usePaymaster,
paymasterType
);
console.log("Gas Estimation for validator installation:");
if (validatorGasEstimate.totalGasFeeInEth) {
console.log(
`Estimated gas fee in ETH: ${ethers.formatEther(
validatorGasEstimate.totalGasFeeInEth
)} ETH`
);
}
// Execute the installation
await axirCore.executeUserOperation(validatorInstallOp);
info
Each module type has different initialization requirements. Social recovery needs guardian addresses and threshold, while ECDSA validator doesn't need initialization data.
warning
Make sure to verify module addresses and types before installation. Using incorrect values could lead to security issues.